package com.eric.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.util.SaResult;
import com.eric.domain.dto.MaterialTypeDto;
import com.eric.service.IMaterialTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 材料类型 前端控制器
 * </p>
 *
 * @author 新哥
 * @since 2024-04-26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/material-type")
public class MaterialTypeController {

    private final IMaterialTypeService materialTypeService;

    //    新增加equip_type
    @PostMapping("/saveOne")
    public SaResult saveOneEqType(@RequestBody MaterialTypeDto materialTypeDto){
        return materialTypeService.saveOneMaterialTypeService(materialTypeDto);
    }
    //    修改equip_type
    @PutMapping("/modifyOne")
    @SaCheckPermission("sys:modify")
    @SaCheckRole(value = {"sys:coder","sys:superAdmin","sys:admin","sys:manager"},mode = SaMode.OR)
    public SaResult modifyOne(@RequestBody MaterialTypeDto materialTypeDto){
        return materialTypeService.modifyOneService(materialTypeDto);
    }

    //    获取所有的equip_type
    @GetMapping("/getAll")
    public SaResult getAll(Integer current,Integer pageSize){
        return materialTypeService.getAllService(current,pageSize);
    }

    //    根据父节点名称模糊查询一级分类
    @GetMapping("/getByPType")
    public SaResult getByName(@RequestParam String parentType,Integer current,Integer pageSize){
        return materialTypeService.getByNameService(parentType,current,pageSize);
    }
    //    根据名称模糊查询二级分类,这个接口可以设定为多功能接口
//    直接可以查询一级分类，二级分类，或者全部分类
    @GetMapping("/getByFullName")
    public SaResult getByFullName(@RequestParam String parentType,@RequestParam String childType,Integer current,Integer pageSize){
        return materialTypeService.getByFullName(parentType,childType,current,pageSize);
    }

    @DeleteMapping("/{id}")
    @SaCheckPermission("sys:delete")
    @SaCheckRole(value = {"sys:coder","sys:superAdmin","sys:admin","sys:manager"},mode = SaMode.OR)
    public SaResult deleteById(@PathVariable("id") Integer id){
        return materialTypeService.deleteByIdService(id);
    }

    @GetMapping("getAllMaterialType")
    public SaResult getAllMaterialType(Integer current,Integer pageSize){
        return materialTypeService.getAllMaterialTypeService(current,pageSize);
    }

    @GetMapping("getAllMaterialTypeCount")
   public SaResult getAllMaterialTypeCount(){
        return materialTypeService.getAllMaterialTypeCountService();
    }

    @GetMapping("/{id}")
    public SaResult getById(@PathVariable("id") Integer id){
        return materialTypeService.getByIdService(id);
    }

}
